import { createWebHashHistory, createRouter } from 'vue-router'
// createWebHistory  相当于router3的 'history'  '/index'
// createWebHashHistory 相当于router3的 'hash'   '/#/index'

// 公共路由
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/index.vue')
  },
  {
    path: '/index',
    component: () => import('@/views/index.vue')
  },
  {
    path: '/login',
    component: () => import('@/views/login.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
